#!/bin/bash

# APK Resign Tool - 密钥库生成模块
# 负责生成新的密钥库文件

# 生成新的密钥库文件
generate_keystore() {
    local keystore_file="$1"
    local alias_name="${2:-my-key-alias}"
    local validity="${3:-10000}"
    local storepass="${4:-android}"
    local keypass="${5:-android}"
    
    if [ -f "$keystore_file" ]; then
        echo "警告：密钥库文件已存在：$keystore_file"
        read -p "是否要覆盖它？(y/n): " confirm
        if [ "$confirm" != "y" ]; then
            echo "操作已取消"
            return 1
        fi
    fi
    
    echo "正在生成新的密钥库文件：$keystore_file"
    keytool -genkey -v -keystore "$keystore_file" -alias "$alias_name" \
        -keyalg RSA -keysize 2048 -validity "$validity" \
        -storepass "$storepass" -keypass "$keypass" \
        -dname "CN=Android Debug,O=Android,C=US"
    
    if [ $? -ne 0 ]; then
        echo "生成密钥库失败"
        return 1
    fi
    
    echo "成功生成密钥库：$keystore_file"
    return 0
} 